package com.ruoyi.fetv.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.fetv.domain.FetvColumn;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.fetv.domain.FetvImage;
import com.ruoyi.fetv.service.IFetvImageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 图片Controller
 *
 * @author lwj
 * @date 2023-02-27
 */
@RestController
@RequestMapping("/fetv/image")
@CrossOrigin
public class FetvImageController extends BaseController
{
    @Autowired
    private IFetvImageService fetvImageService;

    /**
     * 查询图片列表
     */
//    @PreAuthorize("@ss.hasPermi('fetv:image:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(FetvImage fetvImage)
    {
        startPage();
        List<FetvImage> list = fetvImageService.selectFetvImageList(fetvImage);
        return getDataTable(list);
    }

    /**
     * 导出图片列表
     */
//    @PreAuthorize("@ss.hasPermi('fetv:image:export')")
    @Anonymous
    @Log(title = "图片", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FetvImage fetvImage)
    {
        List<FetvImage> list = fetvImageService.selectFetvImageList(fetvImage);
        ExcelUtil<FetvImage> util = new ExcelUtil<FetvImage>(FetvImage.class);
        util.exportExcel(response, list, "图片数据");
    }

    /**
     * 获取图片详细信息
     */
//    @PreAuthorize("@ss.hasPermi('fetv:image:query')")
    @Anonymous
    @GetMapping(value = "/{imageId}")
    public AjaxResult getInfo(@PathVariable("imageId") Long imageId)
    {
        return success(fetvImageService.selectFetvImageByImageId(imageId));
    }

    /**
     * 新增图片
     */
//    @PreAuthorize("@ss.hasPermi('fetv:image:add')")
    @Anonymous
    @Log(title = "图片", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FetvImage fetvImage)
    {
        return toAjax(fetvImageService.insertFetvImage(fetvImage));
    }

    /**
     * 修改图片
     */
//    @PreAuthorize("@ss.hasPermi('fetv:image:edit')")
    @Anonymous
    @Log(title = "图片", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FetvImage fetvImage)
    {
        return toAjax(fetvImageService.updateFetvImage(fetvImage));
    }

    /**
     * 删除图片
     */
//    @PreAuthorize("@ss.hasPermi('fetv:image:remove')")
    @Anonymous
    @Log(title = "图片", businessType = BusinessType.DELETE)
	@DeleteMapping("/{imageIds}")
    public AjaxResult remove(@PathVariable Long[] imageIds)
    {
        return toAjax(fetvImageService.deleteFetvImageByImageIds(imageIds));
    }

    /**
     * 修改状态码
     * id 栏目id
     * status 状态码
     */
    @GetMapping("status")
    @Anonymous
    public AjaxResult editStatus(@RequestParam Long imgid, Integer status)
    {
        FetvImage fetvImage = fetvImageService.selectFetvImageByImageId(imgid);
        fetvImage.setStatus(Long.valueOf(status));
        return toAjax(fetvImageService.updateFetvImage(fetvImage));
    }
}
